package com.share.example.selenium.enums;

import lombok.Getter;

import java.util.Optional;

/**
 * @author syq
 * @data 2019/6/17
 */
@Getter
public enum OperateStatusEnum {
    WILL("0", "即将"),
    EXCEPTION("1", "操作异常"),
    SUCCESS("2", "成功");


    public String code;
    public String name;

    OperateStatusEnum(String code, String name) {
        this.code = code;
        this.name = name;
    }

    public static OperateStatusEnum toEnum(final String code) {
        for (final OperateStatusEnum tag : OperateStatusEnum.values()) {
            if (tag.code.equals(code)) {
                return tag;
            }
        }
        return null;
    }

    public static String toName(final String code) {
        return Optional.ofNullable(toEnum(code)).map(item -> item.name).orElse(null);
    }
}
